package api

import (
	"github.com/gogf/gf/errors/gerror"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/util/gvalid"
	"shrimp-blog-server/app/model"
	"shrimp-blog-server/utils"
)

func (*apiSubject) Get(request *ghttp.Request) {
	subjectService.GetSubjectByID(request, getQueryParamID(request)...)

}

func (*apiSubject) Post(request *ghttp.Request) {
	var subject []model.SubjectRequest
	_ = request.Parse(&subject)
	if e := gvalid.CheckStructWithData(request.Context(), model.SubjectRequest{}, subject, nil); e != nil {
		g.Log().Info(gerror.Current(e))
		utils.Response.ErrorResponseExit(request, gerror.Current(e).Error())
	}
	subjectService.AddSubject(request, subject...)
}

func (*apiSubject) Put(request *ghttp.Request) {
	var subject []model.SubjectRequest
	_ = request.Parse(&subject)
	if e := gvalid.CheckStructWithData(request.Context(), model.SubjectRequest{}, subject, nil); e != nil {
		g.Log().Info(gerror.Current(e))
		utils.Response.ErrorResponseExit(request, gerror.Current(e).Error())
	}
	subjectService.UpdateSubject(request, subject...)
}

func (*apiSubject) Delete(request *ghttp.Request) {
	subjectService.DeleteSubject(request, getQueryParamID(request)...)

}
func (*apiSubject) GetListPage(request *ghttp.Request) {
	subjectService.GetSubjectPage(request, getPage(request))
}
